package user.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

import javax.swing.JScrollPane;

import db.UserValidate;
import javax.swing.JLabel;

public class OnlinesFrame extends JFrame {

	private JPanel contentPane;
	private JTable table;
	private DefaultTableModel tableModel;
	private Vector<String> cols;
	private JLabel lbltypeusermanageradministrator;
	private static OnlinesFrame instOnlines;
	public static OnlinesFrame getInstance()
	{
		if(instOnlines==null)instOnlines=new OnlinesFrame();
		return instOnlines;
	}
	/**
	 * Launch the application.
	 */
	private void flush()
	{
		tableModel.setDataVector(UserValidate.getAccountOnline(), cols);
	}
	

	/**
	 * Create the frame.
	 */
	protected OnlinesFrame() {
		setTitle("users online");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 476);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 10, 414, 385);
		contentPane.add(scrollPane);
		
		table = new JTable();
		scrollPane.setViewportView(table);
		
		JButton btnFlush = new JButton("flush");
		btnFlush.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				flush();
			}
		});
		btnFlush.setBounds(331, 405, 93, 23);
		contentPane.add(btnFlush);
		tableModel=new DefaultTableModel();
		table.setModel(tableModel);
		
		lbltypeusermanageradministrator = new JLabel("(Type:0-User,1-Manager,2-Administrator )");
		lbltypeusermanageradministrator.setBounds(10, 405, 311, 15);
		contentPane.add(lbltypeusermanageradministrator);
		cols=new Vector<String>();
		cols.add("ID");
		cols.add("Type");
		cols.add("Logged Time");
		flush();
		}
}
